package com.yipinhouse.reception.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.house.client.ResoldApartmentManageClient;
import com.yipinhouse.house.client.ResoldHouseManageClient;
import com.yipinhouse.house.client.param.InsertResoldApartmentParam;
import com.yipinhouse.house.client.param.UploadResoldHouseParam;
import com.yipinhouse.reception.client.HouseRecetionManageClient;
import com.yipinhouse.reception.client.param.InsertResoldApartmentWebParam;
import com.yipinhouse.reception.client.param.UploadResoldHouseWebParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/reception")
@Slf4j
public class HouseRecetionManageApiImpl implements HouseRecetionManageClient {
    @Resource
    private ResoldHouseManageClient resoldHouseManageClient;

    @Resource
    private ResoldApartmentManageClient resoldApartmentManageClient;

    @Override
    public Result uploadResoldHouse(UploadResoldHouseWebParam param) {
        log.info("新增出租房：参数：{}",param);
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId1 = request.getHeader("userId");
        Integer userId = Integer.valueOf(userId1);
        UploadResoldHouseParam uploadResoldHouseParam = BeanUtil.copyProperties(param, UploadResoldHouseParam.class);
        uploadResoldHouseParam.setUserId(userId);
        Result result = resoldHouseManageClient.uploadResoldHouse(uploadResoldHouseParam);
        return result;
    }

    @Override
    public Result insertResoldApartment(InsertResoldApartmentWebParam insertResoldApartmentParam) {
        log.info("新增二手房：参数：{}",insertResoldApartmentParam);
        InsertResoldApartmentParam insertResoldApartmentParam1 = BeanUtil.copyProperties(insertResoldApartmentParam, InsertResoldApartmentParam.class);
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId1 = request.getHeader("userId");
        Integer userId = Integer.valueOf(userId1);
        insertResoldApartmentParam1.setUserId(userId);
        Result result = resoldApartmentManageClient.insertResoldApartment(insertResoldApartmentParam1);
        return result;
    }
}
